// packageF/tourAround/tourAroundComm/cityList/cityList.js
Component({
  /**
   * 组件的属性列表
   */
  options: {
    addGlobalClass: true,
  },
  properties: {
    hot:{
      type:Array,
      value:() => []
    },
    cityArr:{
      type:Array,
      value:() => []
    },
    hostCities:{
      type:Array,
      value:() => []
    },
    cityName:{
      type:String,
      value:''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    letter: [], // 右侧数据
    letterShow: true, //是否显示右侧数据
    citiesList: []
  },
  lifetimes: {
    attached: function() {
      // 在组件实例进入页面节点树时执行
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    RelatedSites(event) {
      let {city,citycode} = event.currentTarget.dataset;
      wx.redirectTo({
        url: `/packageF/tourAround/travelIndex/travelIndex?city=${city}&cityCode=${citycode}&localCity=${city}`,
      });
      this.historyCity(city, citycode);
    },
    historyCity(city, cityCode) {
      let arr = wx.getStorageSync("historyList") || [];
      let searchArr = [];
      if (arr.length > 0) {
        arr = JSON.parse(arr);
        let len = arr.length;
        if (len >= 10) {
          arr.pop();
        }
      }
      arr.unshift({ name: city, cityCode: cityCode });
      searchArr = arr.filter((currentValue, currentIndex, selfArr) => {
        //去重
        return selfArr.findIndex(x => x.name === currentValue.name) === currentIndex;
      });
      wx.setStorageSync("historyList", JSON.stringify(searchArr));
    }
  }
})
